﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace WINADM.Server.WMI
{
    public class Win32DependentService
    {
        private string _serviceName;

        public string ServiceName
        {
            get { return _serviceName; }
            set { _serviceName = value; }
        }
        private string _dependentServiceName;

        public string DependentServiceName
        {
            get { return _dependentServiceName; }
            set { _dependentServiceName = value; }
        }

        public Win32DependentService()
        {
        }
        public Win32DependentService(ManagementObject win32DependentService)
        {
            this._serviceName = ExtractName(win32DependentService["Antecedent"]);
            this._dependentServiceName = ExtractName(win32DependentService["Dependent"]);
        }
        private static string ExtractName(object objDependentService)
        {
            if (objDependentService != null)
            {
                string depservice = objDependentService.ToString();
                string[] serviceNamePart = depservice.Split('=');
                if (serviceNamePart.Length == 2)
                {
                    return serviceNamePart[1].Trim('"');
                }

            }
            return String.Empty;
        }
    }
}
